/* ----------------------------------------------------------------------------
* File: quiz_timer.h
*
* Desc: Timer object for quiz
*
* Created: 29/06/2011, by Alexey Korshunov
* ---------------------------------------------------------------------------- */
#ifndef _QUIZ_TIMER_H_
#define _QUIZ_TIMER_H_

#include <memory>

#include "thread_wrapper.h"
#include "logger.h"
#include "exception.h"


namespace QuizCore
{
	class QuizController;

	typedef void (*fpTimeoutCallback)(void*);
	class QuizTimer : public Common::ThreadWrapper
	{
	public:
		QuizTimer(QuizController* parent, fpTimeoutCallback callback) 
			throw(Common::Exception);
		~QuizTimer();

		Common::Error SignalNewQuestion();
		Common::Error SignalCorrectAnswer();

		Common::Error Start();
		Common::Error Stop();

		// ThreadWrapper implementation
		virtual Common::Error Run();

	private:
		QuizController* m_Parent;
		fpTimeoutCallback m_TimeoutCallback;
		HANDLE m_QuestionEvent;
		HANDLE m_AnswerEvent;
		std::auto_ptr<Common::Logger> m_Logger;
	};	
}

#endif // _QUIZ_TIMER_H_